package edu.drexel.cs.eVoter;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;
/**
 * Main/driver class that instantiates 3 evoting servers.
 *
 */
public class EVoter {
	private static Logger logger = Logger.getLogger(EVoter.class);
	public static final String COUNTRY_NAME = "United States of America";
	public static final String[] STATE_NAMES = { "Alabama", "Alaska",
			"American Samoa", "Arizona", "Arkansas", "California", "Colorado",
			"Connecticut", "Delaware", "District of Columbia", "Florida",
			"Georgia", "Guam", "Hawaii", "Idaho", "Illinois", "Indiana",
			"Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland",
			"Massachusetts", "Michigan", "Minnesota", "Mississippi",
			"Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire",
			"New Jersey", "New Mexico", "New York", "North Carolina",
			"North Dakota", "Northern Marianas Islands ", "Ohio", "Oklahoma",
			"Oregon", "Pennsylvania", "Puerto Rico", "Rhode Island",
			"South Carolina", "South Dakota", "Tennessee", "Texas", "Utah",
			"Vermont", "Virginia ", "Virgin Islands ", "Washington",
			"West Virginia", "Wisconsin", "Wyoming " };
	public static final String[] CANDIDATE_NAMES = { "Mitt Romney", "Barack Obama",
			"Iron Man", "Hulk", "Jane Doe" };
	public static final String[] VOTER_IDS = { "Somebody 1", "Somebody 2", "Somebody 3", "Somebody 4", "Somebody 5" };
	public static Map<String, String> voterToStateMap = null; 
	
	public static void main(String[] args) throws Exception {
		voterToStateMap = new HashMap<String, String>();
		voterToStateMap.put("Somebody 1", "Alabama");
		voterToStateMap.put("Somebody 2", "Alaska");
		voterToStateMap.put("Somebody 3", "American Samoa");
		voterToStateMap.put("Somebody 4", "California");
		voterToStateMap.put("Somebody 5", "Florida");
		
		
		Election election = new Election(COUNTRY_NAME, STATE_NAMES,
				CANDIDATE_NAMES, VOTER_IDS, voterToStateMap);
		EVoterServer.setElection(election);
		EVoterServer servers[] = new EVoterServer[3];
		
		// Start up the first 3 states' servers in the state names array.
		for (int i = 0; i < 3; i++) {
			try {
				EVoterServer server = new EVoterServer(STATE_NAMES[i]);
				new Thread(server).start();
				
				servers[i] = server;

			} catch (Throwable t) {
				logger.error(t.getMessage(), t);
			}
		}
		
		// sleep for 60 seconds then kill the first server
		Thread.sleep(60000);

		servers[0].stopServer();
		servers[0] = null;

		// sleep for 60 seconds then kill the second server
		Thread.sleep(60000);

		servers[1].stopServer();
		servers[1] = null;
	}
}
